package com.xunk.system.job;

import com.xunk.system.mapper.SysSceneMapper;
import com.xunk.system.service.ISysSceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.stereotype.Component;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.buz.job
 * @ClassName: FixSceneJob
 * @Author: dongxiaoxin
 * @Description: 固定场景实现
 * @Date: 2021/4/8 15:02
 * @Version: 1.0
 */
@Component
@Configuration
@EnableScheduling
public class FixSceneJob implements SchedulingConfigurer {

    @Autowired
    ISysSceneService service;

    @Autowired
    SysSceneMapper cronMapper;

    /**
     * 执行定时任务.
     */
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {

//        List<SceneQuartzParam> sceneQuartzParams = cronMapper.selectFixScene();
//        for (SceneQuartzParam param : sceneQuartzParams) {
//            Long sceneId = param.getSceneId();
//            List<ControlDeviceParam> params = cronMapper.selectSceneDetail(sceneId,param.getHomeId());
//            taskRegistrar.addTriggerTask(
//                    //1.添加任务内容(Runnable)
//                    () ->service.controlFixScene("", null),
//                    //2.设置执行周期(Trigger)
//                    triggerContext -> {
//                        //2.2 返回执行周期(Date)
//                        return new CronTrigger(param.getCron()).nextExecutionTime(triggerContext);
//                    }
//            );
//        }
    }
}
